﻿// E-Book Copier
// Copyright (C) 2009 Chuan-Gen Fan
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
// 
// Project: http://code.google.com/p/ebookcopier/
// Contact Author:
//    website: http://chuangen.name/
// e-mail/msn: chuangen@live.cn

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace EbookCopier
{
    /// <summary>
    /// 阅览器的状态枚举。
    /// </summary>
    public enum ReaderState
    {
        /// <summary>
        /// 未知
        /// </summary>
        Unknown,
        /// <summary>
        /// 运行中，但没有打开文档
        /// </summary>
        RunningButNoDocument,
        /// <summary>
        /// 运行中，且已经打开文档。
        /// </summary>
        RunningAndOpenDocument,
        /// <summary>
        /// 没有运行。
        /// </summary>
        NotRunning,
    }

    /// <summary>
    /// 阅览器API命令器接口，提供对阅览器翻页等命令的封装。
    /// </summary>
    public interface ICmder
    {
        /// <summary>
        /// 翻到上一页。
        /// </summary>
        void PrevPage();
        /// <summary>
        /// 翻到下一页。
        /// </summary>
        void NextPage();
        /// <summary>
        /// 获取阅览器的状态。
        /// </summary>
        /// <value>阅览器的状态。</value>
        ReaderState ReaderState { get; }
        /// <summary>
        /// Apabi 状态发生变化。
        /// </summary>
        event EventHandler ReaderStateChanged;
        /// <summary>
        /// 属性发生变化。
        /// </summary>
        event EventHandler PropertyChanged;
        /// <summary>
        /// 获取阅览器当前打开的文档标题。
        /// </summary>
        /// <returns>文档标题</returns>
        string GetDocumentTitle();
        /// <summary>
        /// 显示设置对话框。
        /// </summary>
        /// <param name="dialogOwner">对话框的父窗体</param>
        void EditOptions(IWin32Window dialogOwner);
    }
    /// <summary>
    /// 对 ICmder 接口的简单实现。
    /// </summary>
    public abstract class Cmder : ICmder
    {
        #region ICmder 成员
        /// <summary>
        /// 翻到上一页。
        /// </summary>
        public abstract void PrevPage();
        /// <summary>
        /// 翻到下一页。
        /// </summary>
        public abstract void NextPage();

        /// <summary>
        /// 获取阅览器的状态。
        /// </summary>
        /// <value>阅览器的状态。</value>
        public abstract ReaderState ReaderState{ get;}

        /// <summary>
        /// Apabi 状态发生变化。
        /// </summary>
        public event EventHandler ReaderStateChanged;

        /// <summary>
        /// 属性发生变化。
        /// </summary>
        public event EventHandler PropertyChanged;

        /// <summary>
        /// 引发 <see cref="E:ReaderStateChanged"/> 事件。
        /// </summary>
        /// <param name="e">包含事件数据的 <see cref="System.EventArgs"/> 实例。</param>
        protected virtual void OnReaderStateChanged(EventArgs e)
        {
            if (ReaderStateChanged != null)
                ReaderStateChanged(this, e);
        }
        /// <summary>
        /// 引发 <see cref="E:PropertyChanged"/> 事件。
        /// </summary>
        /// <param name="e">包含事件数据的 <see cref="System.EventArgs"/> 实例。</param>
        protected virtual void OnPropertyChanged(EventArgs e)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, e);
        }

        /// <summary>
        /// 获取阅览器当前打开的文档标题。
        /// </summary>
        /// <returns>文档标题</returns>
        public abstract string GetDocumentTitle();
        /// <summary>
        /// 显示设置对话框。
        /// </summary>
        /// <param name="dialogOwner">对话框的父窗体</param>
        public virtual void EditOptions(IWin32Window dialogOwner)
        {
            throw new NotImplementedException("Cmder.EditOptions");
        }

        #endregion
    }
}


 

